﻿using System;
using System.Collections.Generic;
using System.Text;
using Mogre;

namespace AplikacjaOgre
{
    class Program
    {
        private static int oldX =0, deltaX=0, oldY =0, deltaY=0;

        static void Main(string[] args)
        {

            Game.Instance.Inistialise();

            Game.Instance.Terrain = new Terrain();
            Game.Instance.Terrain.setGraphicsMesh("boisko.mesh");
            Game.Instance.Terrain.setCollisonMesh("boisko.mesh");

            Player player = new Player("facio.mesh", 700, 4.5f, new Vector3(0.15f, 0.15f, 0.15f), new Vector3(0, 0.8f, 0));
            player.SetPosition(new Vector3(0, 4, 0));
            Game.Instance.ObjectManager.AddObject(player);

            Game.Instance.GameCamera.Character = player;
            Game.Instance.GameCamera.Distance = 4;
            Game.Instance.GameCamera.Angle = new Degree(20);

            Light light = Game.Instance.SceneManager.CreateLight();
            light.Type = Light.LightTypes.LT_DIRECTIONAL;
            light.Direction = new Vector3(1, -3, 1).NormalisedCopy;
            light.DiffuseColour = new ColourValue(0.2f, 0.2f, 0.2f);


            Game.Instance.SceneManager.ShadowTechnique = ShadowTechnique.SHADOWTYPE_STENCIL_MODULATIVE;

            int i=0, j = 0;

            Game.Instance.startManualControlling(player, i, j);

            Game.Instance.Mouse.MouseMoved += new MOIS.MouseListener.MouseMovedHandler(Mouse_MouseMoved);

           

            while (true)
            {
                Game.Instance.Update();

                if (Game.Instance.Keyboard.IsKeyDown(MOIS.KeyCode.KC_R))
                {
                    System.Console.WriteLine("aaaa");
                    Game.Instance.sys.Dispose();
                }

                if (Game.Instance.Keyboard.IsKeyDown(MOIS.KeyCode.KC_Q))
                {
                    Game.Instance.Shutdown();
                    break;
                }

                if (Game.Instance.Keyboard.IsKeyDown(MOIS.KeyCode.KC_LEFT))
                    //Game.Instance.startManualControlling(player, i, j++);
                    player.Orientation *= Vector3.UNIT_Z.GetRotationTo(new Vector3(0.1f, 0, 1.0f).NormalisedCopy);

                if (Game.Instance.Keyboard.IsKeyDown(MOIS.KeyCode.KC_RIGHT))
                    //Game.Instance.startManualControlling(player, i++, j);
                    player.Orientation *= Vector3.UNIT_Z.GetRotationTo(new Vector3(-0.1f, 0, 1.0f).NormalisedCopy);

                if (Game.Instance.Keyboard.IsKeyDown(MOIS.KeyCode.KC_UP))
                    player.PlayerState = PlayerState.WALK;
                else
                    player.PlayerState = PlayerState.IDLE;

                if(Game.Instance.Mouse.MouseState.ButtonDown(MOIS.MouseButtonID.MB_Right))
                    Game.Instance.GameCamera.Distance += deltaY;

                if (Game.Instance.Keyboard.IsKeyDown(MOIS.KeyCode.KC_F10))
                   Game.Instance.NewtonDebugger.ShowDebugInformation();
                else
                   Game.Instance.NewtonDebugger.HideDebugInformation();
            }
        }

        private static bool Mouse_MouseMoved(MOIS.MouseEvent ev)
        {
            deltaY = oldY - ev.state.Y.abs;
            oldY = ev.state.Y.abs;

            return true;
        }
    }
}
